package com.sgb.kjwl.view.ui.adapter.enterprise;

import android.content.Context;
import android.text.TextUtils;

import com.google.gson.Gson;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemServiceDetailDealedCasesBinding;
import com.sgb.kjwl.model.entity.enterprise.TransactionCasesEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class DealedCasesDetailAdapter extends BaseRecycleAdapter<TransactionCasesEntity> {

    Context context;
    ItemServiceDetailDealedCasesBinding binding;

    public DealedCasesDetailAdapter(Context context, List<TransactionCasesEntity> datas) {
        super(context, R.layout.item_service_detail_dealed_cases, datas);
        this.context = context;
    }

    @Override
    public void convert(ItemViewHolder holder, TransactionCasesEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        binding = (ItemServiceDetailDealedCasesBinding) holder.getmBinding();
        binding.tvCategoryValue.setText(entity.getTransactionServiceName());
        binding.tvServiceStatus.setText(entity.getServiceStatus() == -1 ? "办理中" : "已完成");
        binding.tvServiceCustomer.setText(entity.getServeCustomers());
        String provinceCode = entity.getProvincesCode();
        Gson gson = new Gson();
        TransactionCasesEntity.ProvinceCode provinceCodeEntity = gson.fromJson(provinceCode, TransactionCasesEntity.ProvinceCode.class);
        StringBuilder builder = new StringBuilder();
        builder.append(provinceCodeEntity.getProvinceName());
        if (!TextUtils.isEmpty(provinceCodeEntity.getCityName())) {
            builder.append("-").append(provinceCodeEntity.getCityName());
        }
        if (!TextUtils.isEmpty(provinceCodeEntity.getAreaName())) {
            builder.append("-").append(provinceCodeEntity.getAreaName());
        }
        binding.tvServiceCity.setText(builder.toString());
    }
}
